<?php

namespace Lib\Db;

class MysqlConnect extends \Home {

	public $pdoBox = array();

	protected function __construct() {

	}

	public function connect($dsn, $user, $password, $options, &$key) {
		ksort($options);
		$key = md5($dsn . $user . $password . json_encode($options));
		if (!empty($this->pdoBox[$key])) {
			return $this->pdoBox[$key];
		}
		$this->pdoBox[$key] = new \PDO($dsn, $user, $password, $options);
		return $this->pdoBox[$key];
	}

	public function disconnect($key) {
		if (isset($this->pdoBox[$key])) {
			unset($this->pdoBox[$key]);
		}
	}
}